package com.ncu.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.ncu.web.entry.Majority;
import com.ncu.web.service.MajorityService;
import com.ncu.web.util.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MajorityController {

    @Autowired
   private MajorityService baseService;

    @GetMapping("/majority/get/all")
    @ResponseBody
    public String returnMajority(){

        List<Majority> majorityList = baseService.selectAllMajorityInformation();

        if(majorityList.isEmpty()){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", Code.USER_OP_FAIL);
            jsonObject.put("msg", "专业查询失败");
            return jsonObject.toJSONString();
        }else{
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", Code.USER_OP_SUCCESS);
            jsonObject.put("msg", "专业查询成功");
            jsonObject.put("data",majorityList);
            return jsonObject.toJSONString();
        }
    }
}
